import router from "../router";
import {getToken, setChannelId} from "./auth";

const whiteList = ["/login", "/home", "/register", "/share", "/findloan"];
router.beforeEach((to, from, next) => {
    //记录当前地址
    if (to.query.channelId != undefined) {
        setChannelId(to.query.channelId)
    }
    let loginToken = getToken();
    if (loginToken || whiteList.indexOf(to.path) > -1) {
        //登录状态 或者白名单 直接放行
        //ios的话 记录首次进入的地址
        next();
    } else {
        //跳转到登录页面
        router.push({
            path: "/login"
        });
    }
});
